function [setting,agc,gardner,pll,detection,frameSync,eq] = init()
% 参数初始化函数，首字母大写表示常量，首字母小写表示变量
%% 总体参数
    setting.Fs = 60e6;
    setting.Fd = 1e3;
    setting.Pilot_Len = 64;
    setting.Pilot_Time = 8;
    setting.FrameSync_Len = 32;
    setting.Msg_Len = 2000;
    setting.M = 4;
    setting.OSR = 4;
    
    setting.Rcos_Beta = 0.5;
    setting.Rcos_span = 6;
    
    setting.SNR = 20;
    
%% AGC参数
    agc.A = log(1);
    agc.g = 0;
    agc.N = 128; % update period
    agc.K= 1/2^12; % step size
    agc.window = zeros(1,agc.N); % sliding window calculating the pwr of N signals
    agc.output = 0;
    agc.out_window = zeros(1,agc.N);
    agc.cnt_s = 0;
    agc.cnt_f = 0;
    agc.cnt_s_target = 1e4;
    agc.cnt_f_target = 1e3;
    agc.flag_steady = 0;
 
%% detection检测参数
    detection.Window_Len = (setting.Pilot_Len-1)*setting.OSR+1+...
                                setting.OSR*setting.Rcos_span;
    detection.input_window = zeros(1,detection.Window_Len);
    detection.c_window = zeros(detection.Window_Len,1);
    detection.window_cnt = 0;
    detection.PARP_Threshold = 12;
    detection.A = 1600;
    detection.flag_detected = 0;
    detection.num = 0;
    detection.cnt = 0;   
    
%%  Pll载波同步参数
    pll.phase = 0; % 32bits, unsigned
    pll.ftw = 0; % 16bits, signed
    pll.phase_error = 0; % 32bits
    pll.loopfilter = 0; % 16bits'
    pll.output = 0;
    pll.flag_locked = 0;
    pll.filter_window = zeros(1,1024);
    pll.Threshold = 2e4;
    pll.lock_cnt = 0;
    pll.Lock_target = 4000;
    
    pll.watch.phase = [];
    pll.watch.filter = []; 
    
%% Gardner位同步参数
    gardner.i_valid = 0;
    gardner.input = zeros(4,1);
    gardner.cnt = 0;
    gardner.cnt_next = 0;
    gardner.mu = 0;
    gardner.mu_next = 0;
    gardner.TEDBuffer = zeros(1,3);
    gardner.underflow = 0;
    gardner.k1 = -0.0059;
    gardner.k2 = -2.3515e-5;
    gardner.vp = 0;
    gardner.vi = 0;
    gardner.v = 0;
    gardner.o_valid = 0;
    gardner.output = 0;

    gardner.mu_window = zeros(2048,1);
    gardner.mu_cnt = 0;
    gardner.flag_locked = 0;
    gardner.Threshold = 0.01;
    gardner.lock_cnt = 0;
    gardner.watch.v = [];
    
%% frameSync帧同步参数
    frameSync.Threshold = 40;
    frameSync.window = zeros(1,setting.FrameSync_Len);
    frameSync.c0_window = zeros(setting.FrameSync_Len,1);
    frameSync.c90_window = zeros(setting.FrameSync_Len,1);
    frameSync.c180_window = zeros(setting.FrameSync_Len,1);
    frameSync.c270_window = zeros(setting.FrameSync_Len,1);
    frameSync.detected = 0;

%% equalizer均衡参数
    eq.Tap_Len = 12;
    eq.Ref_Len = 6;
    eq.weight = zeros(eq.Tap_Len,1);
    eq.weight(eq.Ref_Len) = 1;
    eq.input = zeros(eq.Tap_Len,1);
    eq.output = 0;
    eq.e = 0;
    eq.mu = 2^-5;
    eq.d = [];
    
    
end

